package cn.yunhe.servlet;

import com.zhenzi.sms.ZhenziSmsClient;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 王羊
 */

@WebServlet("/Duanxinyanzheng")
public class Duanxinyanzheng extends HttpServlet {

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PrintWriter out = response.getWriter();
        String yy="";
        //产生四个随机数 作为验证码
        for (int i = 0; i <4; i++) {
            yy+=(int)(Math.random()*9+1);
        }
        //储存验证码
        request.getSession().setAttribute("yan",yy);
        //短信程序  收费
        ZhenziSmsClient client = new ZhenziSmsClient("https://sms_developer.zhenzikj.com", "101352", "bc6d309b-a816-4cb3-bbb7-043568978bb6");
        String result="";

        try {
            result = client.send(request.getParameter("tel"), "您的验证码："+yy+"，您正进行身份验证，打死不告诉别人！");
        } catch (Exception e) {
            e.printStackTrace();
        }
        out.print(result);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}


